//
//  FGRecordBottomView.m
//  VocieRecorder
//
//  Created by Fengur on 16/9/1.
//  Copyright © 2016年 code.uworks.fengur. All rights reserved.
//

#import "FGRecordBottomView.h"

@implementation FGRecordBottomView

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupControls];
        [self setControlsLayOut];
    }
    return self;
}

- (void)setupControls {
    self.backgroundColor = [UIColor whiteColor];
    _makePointBtn = [[UIButton alloc] init];
    [_makePointBtn setImage:ImageOfName(@"") forState:UIControlStateNormal];
    _makePointBtn.backgroundColor = [UIColor whiteColor];
    [_makePointBtn setTitle:@"打点" forState:UIControlStateNormal];
    [_makePointBtn setTitleColor:BPTitleColor forState:UIControlStateNormal];
    _makePointBtn.titleLabel.font = AvenirMedium(14.f);
    _makePointBtn.layer.borderWidth = 0.5;
    [_makePointBtn addTarget:self
                      action:@selector(makePoint)
            forControlEvents:UIControlEventTouchUpInside];
    _makePointBtn.layer.borderColor = [UIColor grayColor].CGColor;
    [self addSubview:_makePointBtn];

    _saveBtn = [[UIButton alloc] init];
    [_saveBtn setImage:ImageOfName(@"") forState:UIControlStateNormal];
    _saveBtn.backgroundColor = [UIColor whiteColor];
    [_saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [_saveBtn setTitleColor:BPTitleColor forState:UIControlStateNormal];
    _saveBtn.titleLabel.font = AvenirMedium(14.f);
    _saveBtn.layer.borderWidth = 0.5;
    _saveBtn.layer.borderColor = [UIColor grayColor].CGColor;
    [self addSubview:_saveBtn];

    _startBtn = [[UIButton alloc] init];
    [_startBtn setImage:ImageOfName(@"") forState:UIControlStateNormal];
    _startBtn.backgroundColor = [UIColor whiteColor];
    _startBtn.layer.borderWidth = 0.5;
    [_startBtn setTitle:@"开始" forState:UIControlStateNormal];
    _startBtn.selected = NO;
    [_startBtn setTitle:@"继续" forState:UIControlStateSelected];
    [_startBtn setTitleColor:BPTitleColor forState:UIControlStateNormal];
    _startBtn.titleLabel.font = AvenirMedium(14.f);
    _startBtn.layer.borderColor = [UIColor grayColor].CGColor;
    [_startBtn addTarget:self
                  action:@selector(startRecord)
        forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_startBtn];
}

- (void)setControlsLayOut {
    CGFloat startButtonWidhth = [FGSizeTool widthWithSize6:60];
    CGFloat saveButtonWidth = [FGSizeTool widthWithSize6:45];
    _makePointBtn.layer.cornerRadius = saveButtonWidth / 2;
    _saveBtn.layer.cornerRadius = saveButtonWidth / 2;
    _startBtn.layer.cornerRadius = startButtonWidhth / 2;
    CGFloat leftPading = (ScreenWidth - startButtonWidhth - saveButtonWidth * 2) / 8;

    [_makePointBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(leftPading);
        make.width.mas_equalTo(saveButtonWidth);
        make.height.mas_equalTo(saveButtonWidth);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];

    [_saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-leftPading);
        make.width.mas_equalTo(saveButtonWidth);
        make.height.mas_equalTo(saveButtonWidth);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];

    [_startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(startButtonWidhth);
        make.height.mas_equalTo(startButtonWidhth);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
}

- (void)startRecord {
    _startBtn.selected = !_startBtn.selected;
    [self.delegate startOrEndRecording];
}

- (void)makePoint {
    [self.delegate makePoints];
}

@end
